<template>
    <div v-if="load">
        <div class="title">{{ anIndexEvaluationMain.reginName }}数据填报</div>
        <div class="sub-title">
            <div>所属区县：{{ anIndexEvaluationMain.reginName }}</div>
            <div>填报人：{{ anIndexEvaluationMain.auditBy }}</div>
            <div>填报日期：{{ anIndexEvaluationMain.lstUpdTime }}</div>
            <div>指标总数：{{ anIndexEvaluationMain.totalQuestionNums }}</div>
            <div>当前填报序号：{{ anIndexEvaluationMain.currQuestionSeq }}</div>
        </div>
        <div class="btn-box">
            <div v-if="controlType !== 'area'">
                <span style="margin-right: 10px;">请选择正确的指标序号</span>
                <el-input-number v-model="keyword" :max="anIndexEvaluationMain.totalQuestionNums"
                                 :min="1"></el-input-number>
                <el-button style="margin-left: 10px;" type="primary" @click="handleChangeSeq">跳转</el-button>
            </div>
            <div>
                <el-button v-if="anIndexEvaluationMain.currQuestionSeq !== 1  || editProgress === 'main'"
                           @click="before">上一项
                </el-button>
                <el-button v-if="editProgress === 'detail'" type="primary" @click="next">下一项</el-button>
                <el-button @click="storageData('Tem')">暂存</el-button>
                <el-button v-if="editProgress === 'detail'" type="primary" @click="openMainBaseInfo">基本信息填报
                </el-button>

                <!--                <el-button type="primary" @click="allSave" v-if="controlType === 'area' && editProgress === 'main'">保存填报内容</el-button>-->
                <el-button v-if="editProgress === 'main' && controlType === 'city'||controlType === 'province'"
                           type="danger" @click="cityReject">
                    驳回
                </el-button>
                <el-button v-if="editProgress === 'main' && controlType === 'area'" type="primary"
                           @click="saveMain('area')">完成填报
                </el-button>
                <el-button v-if="editProgress === 'main' && controlType === 'admin'" type="danger"
                           @click="returnAdmin">管理员驳回
                </el-button>
                <el-button v-if="editProgress === 'main' && controlType === 'admin'" type="primary"
                           @click="expertAdmin">管理员确认
                </el-button>
                <el-button v-if="editProgress === 'main' && controlType === 'expert'" type="primary"
                           @click="expertAudit">完成评估
                </el-button>
                <!--                <el-button v-if="editProgress === 'main' && controlType === 'expert'||controlType === 'view'"-->
                <!--                           type="primary"-->
                <!--                           @click="viewIndexDtl">建议明细-->
                <!--                </el-button>-->
                <el-button v-if=" controlType === 'view'" type="primary"
                           @click="returnList">返回列表
                </el-button>
                <el-button v-if="editProgress === 'main' && controlType === 'city'" type="primary" @click="cityAudit">
                    市审批通过
                </el-button>
                <el-button v-if="editProgress === 'main' && controlType === 'province'" type="primary"
                           @click="provinceAudit">
                    省审批通过
                </el-button>
            </div>
        </div>
        <div>
            <el-form v-if="editProgress === 'detail'" ref="targetForm" class="demo-ruleForm" label-width="100px">
                <el-row>
                    <el-col v-if="currentIndexInfo.anBasIndex.biz1 === '2'" :span="24">
                        <el-form-item label="上级指标">
                            <el-input v-model="currentIndexInfo.anBasIndex.biz4" disabled></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="6">
                        <el-form-item label="指标代码">
                            <el-input v-model="currentIndexInfo.anBasIndex.indexCode" disabled></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="18">
                        <el-form-item label="指标信息">
                            <el-input v-model="currentIndexInfo.anBasIndex.indexDesc" disabled></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="20" hidden="true">
                    <el-col :span="6">
                        <el-form-item label="指标代码">
                            <el-input v-model="currentIndexInfo.anBasIndex.indexCode" disabled></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6" hidden="true">
                        <el-form-item label="评估年度">
                            <el-input v-model="currentIndexInfo.anBasIndex.estimateYear" disabled></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6" hidden="true">
                        <el-form-item label="自评时间">
                            <el-input v-model="anIndexEvaluationMain.lstUpdTime" disabled></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6" hidden="true">
                        <el-form-item label="自评人员">
                            <el-input v-model="anIndexEvaluationMain.createBy" disabled></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-table
                            :data="anIndexAbilityOptionsList"
                            border
                            height="260"
                            style="margin-bottom: 10px"
                    >
                        <el-table-column
                                label="等级"
                                width="150">
                            <template slot-scope="scope">
                                <el-tag size="medium">{{ scope.row.optionsCode }}</el-tag>
                            </template>
                        </el-table-column>

                        <el-table-column
                                label="等级描述"
                                width="1200">
                            <template slot-scope="scope">
                                <!--                                <el-tag size="medium">{{ scope.row.optionsDesc }}</el-tag>-->
                                <div>{{ scope.row.optionsDesc }}</div>
                            </template>
                        </el-table-column>
                    </el-table>
                </el-row>
                <el-row>
                    <el-col :span="6">
                        <el-form-item label="自评能力等级">
                            <el-select v-model="scoreList[0].score" :disabled="controlType !== 'area'"
                                       placeholder="请选择能力等级">
                                <el-option v-for="(score,index) in anIndexAbilityOptionsList" :key="index"
                                           :label="score.optionsCode" :value="score.status"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <!--                <el-row v-for="(level,index) in scoreList" :key="index">-->
                <!--                    <el-col :span="6">-->
                <!--                        <el-form-item label="自评能力项目">-->
                <!--                            <el-input :value="level.optionDesc" disabled></el-input>-->
                <!--                        </el-form-item>-->
                <!--                    </el-col>-->
                <!--                    <el-col :span="6">-->
                <!--                        <el-form-item label="自评能力等级">-->
                <!--                            <el-select v-model="level.score" placeholder="请选择能力等级" :disabled="controlType !== 'area'">-->
                <!--                                <el-option :label="score.level" :value="score.score" v-for="(score,index) in levelList" :key="index"></el-option>-->
                <!--                            </el-select>-->
                <!--                        </el-form-item>-->
                <!--                    </el-col>-->
                <!--                </el-row>-->

                <el-form-item label="自评概述" prop="reginEvalBiz" @dblclick="copyBaseGs">
                    <el-input v-model="currentEvalDtl.reginEvalLack" :disabled="controlType !== 'area'"
                              :maxlength="1000" type="textarea"></el-input>
                    <el-button v-if="controlType === 'expert'" style="margin-top: 5px;" type="primary"
                               @click="copyBaseGs">复制自评概述
                    </el-button>
                </el-form-item>
                <el-form-item label="自评不足" prop="reginEvalBz">
                    <el-input v-model="currentEvalDtl.reginEvalBiz" :disabled="controlType !== 'area'"
                              :maxlength="4000" type="textarea"></el-input>
                </el-form-item>

                <el-form-item label="上传材料">
                    <mul-pic-upload :affixList="affixList" :disabled="controlType !== 'area'" :value="affixListStr"
                                    @input="fileUpload"/>
                </el-form-item>
                <el-divider v-if="controlType === 'expert' || controlType === 'view' || controlType === 'admin'">
                    以下信息为专家填写信息
                </el-divider>
                <el-row v-if="controlType === 'expert' || controlType === 'view' || controlType === 'admin'" :gutter="20">
                    <el-col :span="6">
                        <el-form-item label="能力等级">
                            <el-select v-model="scoreList[0].expertScore" :disabled="controlType !== 'expert'"
                                       placeholder="请选择专家评估能力等级" required>
                                <el-option v-for="(score,index) in anIndexAbilityOptionsList" :key="index"
                                           :label="score.optionsCode" :value="score.status"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="评估时间">
                            <el-input v-model="currentEvalDtl.expertEvalTime" disabled></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="评估人员">
                            <el-input v-model="currentEvalDtl.expertEvayBy" disabled></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-form-item v-if="controlType === 'expert' || controlType === 'view' || controlType === 'admin'" label="评估结果">
                    <el-input v-model="currentEvalDtl.evaluationDtlBiz.expertEvalResult"
                              :disabled="controlType !== 'expert'"
                              :maxlength="4000"
                              rows="4" type="textarea"></el-input>
                </el-form-item>
                <el-form-item v-if="controlType === 'expert' || controlType === 'view' || controlType === 'admin'" label="存在主要短板">
                    <el-input v-model="currentEvalDtl.expertEvalLack" :disabled="controlType !== 'expert'"
                              :maxlength="4000"
                              rows="4" type="textarea"></el-input>
                </el-form-item>
                <el-form-item v-if="controlType === 'expert' || controlType === 'view' || controlType === 'admin'" label="主要建议">
                    <el-input v-model="currentEvalDtl.expertEvalBiz" :disabled="controlType !== 'expert'"
                              :maxlength="1000"
                              rows="4" type="textarea"></el-input>
                </el-form-item>

            </el-form>
            <div v-if="editProgress === 'main'">
                <el-form ref="ruleForm" class="demo-ruleForm" label-width="140px">
                    <!--     专家独立控制，按照tab分页。 原来的逻辑都在else里边，没动     -->
                    <template v-if="controlType === 'expert' || controlType === 'view' || controlType === 'admin'">
                        <el-tabs type="border-card">
                            <el-tab-pane label="评估概述和基本情况">
                                <el-form-item label="评估概况"
                                              prop="expertEvalSummary">
                                    <el-input v-model="anIndexEvaluationMain.evaluationMainBizExpert.expertEvalSummary"
                                              :disabled="controlType === 'view'" :maxlength="1000" rows="10"
                                              type="textarea"></el-input>
                                </el-form-item>
                                <el-form-item label="评估基本情况"
                                              prop="expertEvalBaseinfo">
                                    <el-input v-model="anIndexEvaluationMain.evaluationMainBizExpert.expertEvalBaseinfo"
                                              :disabled="controlType === 'view'" :maxlength="1000" rows="10"
                                              type="textarea"></el-input>
                                </el-form-item>
                            </el-tab-pane>
                            <el-tab-pane label="畜牧业发展情况">
                                <el-button style="float: right;margin-bottom: 10px;" type="primary"
                                           @click="openMainBaseInfo">基本信息填报
                                </el-button>
                                <el-form-item label="畜牧业发展情况"
                                              prop="expertEvalAnimalHusband"
                                              style="clear: both;">
                                    <el-input
                                            v-model="anIndexEvaluationMain.evaluationMainBizExpert.expertEvalAnimalHusband"
                                            :disabled="controlType === 'view'" :maxlength="1000" rows="10"
                                            type="textarea"></el-input>
                                </el-form-item>
                            </el-tab-pane>
                            <el-tab-pane label="总体评估结果">
                                <el-button style="margin-bottom: 10px;" type="primary"
                                           @click="viewIndexDtl">建议明细
                                </el-button>
                                <el-form-item label="第一章"
                                              prop="expertEvalOverallReaults1">
                                    <el-input
                                            v-model="anIndexEvaluationMain.evaluationMainResult1Expert.expertEvalOverallReaults1"
                                            :disabled="controlType === 'view'" :maxlength="4000" rows="10"
                                            type="textarea"></el-input>
                                </el-form-item>
                                <el-form-item label="第二章"
                                              prop="expertEvalOverallReaults2">
                                    <el-input
                                            v-model="anIndexEvaluationMain.evaluationMainResult2Expert.expertEvalOverallReaults2"
                                            :disabled="controlType === 'view'" :maxlength="4000" rows="10"
                                            type="textarea"></el-input>
                                </el-form-item>
                                <el-form-item label="第三章"
                                              prop="expertEvalOverallReaults3">
                                    <el-input
                                            v-model="anIndexEvaluationMain.evaluationMainResult3Expert.expertEvalOverallReaults3"
                                            :disabled="controlType === 'view'" :maxlength="4000" rows="10"
                                            type="textarea"></el-input>
                                </el-form-item>
                                <el-form-item label="第四章"
                                              prop="expertEvalOverallReaults4">
                                    <el-input
                                            v-model="anIndexEvaluationMain.evaluationMainResult4Expert.expertEvalOverallReaults4"
                                            :disabled="controlType === 'view'" :maxlength="1000" rows="10"
                                            type="textarea"></el-input>
                                </el-form-item>
                            </el-tab-pane>
                            <el-tab-pane label="短板和建议">
                                <el-button style="float: right;margin-bottom: 10px;" type="primary"
                                           @click="viewIndexDtl">建议明细
                                </el-button>
                                <el-form-item label="整体短板"
                                              prop="expertLack"
                                              style="clear: both;">
                                    <el-input v-model="anIndexEvaluationMain.expertLack" :disabled="controlType === 'view'" :maxlength="4000"
                                              rows="10" type="textarea"></el-input>
                                </el-form-item>
                                <el-form-item label="专家建议"
                                              prop="expertBiz">
                                    <el-input v-model="anIndexEvaluationMain.expertBiz" :disabled="controlType === 'view'" :maxlength="1000"
                                              rows="10" type="textarea"></el-input>
                                </el-form-item>
                            </el-tab-pane>
                        </el-tabs>
                    </template>
                    <template v-else>
                        <el-form-item label="区县整体自评意见">
                            <el-input v-model="anIndexEvaluationMain.reginEvalDesc" :disabled="controlType !== 'area'"
                                      :maxlength="1000" placeholder="提示:工作亮点、短板、建议" rows="10"
                                      type="textarea"></el-input>
                        </el-form-item>
                        <el-form-item v-if="controlType === 'city'" label="市审批意见" prop="auditDesc">
                            <el-input v-model="anIndexEvaluationMain.auditDesc"
                                      :disabled="controlType === 'expert' || controlType === 'view' || controlType === 'admin'"
                                      :maxlength="1000" rows="10" type="textarea"></el-input>
                        </el-form-item>
                        <el-form-item v-if="controlType === 'province'" label="省审批意见" prop="auditDesc">
                            <el-input v-model="anIndexEvaluationMain.confirmDesc"
                                      :disabled="controlType === 'expert' || controlType === 'view' || controlType === 'admin'"
                                      :maxlength="1000" rows="10" type="textarea"></el-input>
                        </el-form-item>
                        <!--                        <el-form-item v-if="controlType === 'expert'||controlType === 'view'" label="整体短板"-->
                        <!--                                      prop="expertLack">-->
                        <!--                            <el-input v-model="anIndexEvaluationMain.expertLack" rows="10" type="textarea" :disabled="controlType === 'view'" :maxlength="4000"></el-input>-->
                        <!--                        </el-form-item>-->
                        <!--                        <el-form-item v-if="controlType === 'expert'||controlType === 'view'" label="专家建议"-->
                        <!--                                      prop="expertBiz">-->
                        <!--                            <el-input v-model="anIndexEvaluationMain.expertBiz" rows="10" type="textarea" :disabled="controlType === 'view'" :maxlength="1000"></el-input>-->
                        <!--                        </el-form-item>-->
                    </template>
                </el-form>
            </div>
            <div class="btn-box">
                <div v-if="controlType !== 'area'">
                    <span style="margin-right: 10px;">请选择正确的指标序号</span>
                    <el-input-number v-model="keyword" :max="anIndexEvaluationMain.totalQuestionNums"
                                     :min="1"></el-input-number>
                    <el-button style="margin-left: 10px;" type="primary" @click="handleChangeSeq">跳转</el-button>
                </div>
                <div>
                    <el-button v-if="anIndexEvaluationMain.currQuestionSeq !== 1 || editProgress === 'main'"
                               @click="before">上一项
                    </el-button>
                    <el-button v-if="editProgress === 'detail'" type="primary" @click="next">下一项</el-button>
                    <el-button @click="storageData('Tem')">暂存</el-button>
                    <el-button v-if="editProgress === 'main' && controlType === 'admin'" type="danger"
                               @click="returnAdmin">管理员驳回
                    </el-button>
                    <el-button v-if="editProgress === 'main' && controlType === 'admin'" type="primary"
                               @click="expertAdmin">管理员确认
                    </el-button>
                    <!--                <el-button type="primary" @click="allSave" v-if="controlType === 'area' && editProgress === 'main'">保存填报内容</el-button>-->
                    <el-button v-if="editProgress === 'main' && controlType === 'city'" type="danger"
                               @click="cityReject">
                        驳回
                    </el-button>
                    <el-button v-if="editProgress === 'main' && controlType === 'area'" type="primary"
                               @click="saveMain('area')">完成填报
                    </el-button>
                    <el-button v-if="editProgress === 'main' && controlType === 'expert'" type="primary"
                               @click="expertAudit">完成评估
                    </el-button>
                    <!--                    <el-button v-if="editProgress === 'main' && controlType === 'expert'" type="primary"-->
                    <!--                               @click="viewIndexDtl">建议明细-->
                    <!--                    </el-button>-->
                    <el-button v-if="editProgress === 'main' && controlType === 'view'" type="primary"
                               @click="returnList">返回列表
                    </el-button>

                    <el-button v-if="editProgress === 'main' && controlType === 'city'" type="primary"
                               @click="cityAudit">
                        市审批通过
                    </el-button>
                    <el-button v-if="editProgress === 'main' && controlType === 'province'" type="primary"
                               @click="provinceAudit">
                        省审批通过
                    </el-button>
                </div>
            </div>
        </div>
        <indexauditdtl v-if="auditDtlVisible" ref="auditdtl"></indexauditdtl>
        <mainbaseinfo v-if="baseinfoVisible" ref="baseinfo" :disable="controlType !== 'area'"></mainbaseinfo>
    </div>
</template>

<script>
import MulPicUpload from '@/components/mul-pic-upload/index.vue'
import indexauditdtl from './indexauditdtl'
import mainbaseinfo from './mainbaseinfo'
import {levelList} from '@/utils/data'

export default {
	components: {MulPicUpload, indexauditdtl, mainbaseinfo},
	props: {
		// 权限控制// area -- 区县   city -- 省市 province--省份  expert -- 专家
		controlType: {
			type: String,
			default: 'area'
		},
		editFormData: {
			type: Object,
			default: (() => {
				return {}
			})
		}
	},
	computed: {},
	data () {
		return {
			load: false,//
			keyword: 1,
			editProgress: 'detail',//填报进度。 主页面 or 指标详情页面
			targetIndex: 0,
			auditDtlVisible: false,
			baseinfoVisible: false,
			ruleForm: {
				reginEvalDesc: '',
				auditDesc: '',
				expertBiz: '',
				expertLack: ''
			},
			rules: {
				reginEvalDesc: [
					{required: true, message: '请输入整体自评意见', trigger: 'blur'}
				],
				expertBiz: [
					{required: true, message: '请输入专家评估整体意见', trigger: 'blur'}
				],
				auditDesc: [
					{required: true, message: '请输入市审批意见', trigger: 'blur'}
				],
				confirmDesc: [
					{required: true, message: '请输入省审批意见', trigger: 'blur'}
				],
				score: [
					{required: true, message: '能力等级不能为空', trigger: 'change'}
				],
				expertScore: [
					{required: true, message: '请选择评估等级', trigger: 'change'}
				],
			},
			levelList: [],

			affixList: [],
			affixListStr: '',
			anIndexEvaluationMain: {},
			currentEvalDtl: {},
			currentIndexInfo: {},
			scoreList: [],
			anIndexAbilityOptionsList: []
		}
	},
	mounted () {
		this.editProgress = 'detail'
		this.initData()
	},
	methods: {
		initData () {
			// this.editFormData = JSON.parse(sessionStorage.areaInitFormData);
			console.log('🚀 ~ this.editFormData', this.editFormData)
			this.load = false
			this.affixList = this.editFormData.affixList
			let affixPathList = []
			this.affixList.forEach((img) => {
				affixPathList.push(img.affixPath)
			})
			console.log('🚀 ~ affixPathList', affixPathList)
			this.affixListStr = affixPathList.length ? affixPathList.join(',') : ''
			this.anIndexEvaluationMain = this.editFormData.anIndexEvaluationMain
			this.currentEvalDtl = this.editFormData.currentEvalDtl
			console.log('🚀 ~ this.currentEvalDtl', this.currentEvalDtl)
			this.currentIndexInfo = this.editFormData.currentIndexInfo
			this.anIndexAbilityOptionsList = this.editFormData.currentIndexInfo.anIndexAbilityOptionsList.sort(wfy.sortBy('optionsCode'))

			this.anIndexEvaluationMain.auditBy = this.controlType === 'area' ? this.$store.state.user.name : this.anIndexEvaluationMain.auditBy
			console.log('🚀 ~ this.anIndexAbilityOptionsList', this.anIndexAbilityOptionsList)
			this.scoreList = this.editFormData.scoreList
			let areaList = this.$store.state.user.area.area
			let regin = areaList.find((item) => {
				return item.code === this.anIndexEvaluationMain.reginId
			})
			this.anIndexEvaluationMain.reginName = regin.name
			if (this.controlType === 'expert') {
				this.currentEvalDtl.expertEvalTime = wfy.format('yyyy-MM-dd HH:mm:ss', new Date())
				this.currentEvalDtl.expertEvalBy = this.$store.state.user.name
			}
			this.$nextTick(() => {
				this.load = true
			})
		},
		fileUpload (fileList) {
			console.log('🚀 ~ file', fileList)
			const loading = this.$loading({
				lock: true,
				text: '图片上传中',
				spinner: 'el-icon-loading',
				background: 'rgba(0, 0, 0, 0.7)'
			})
			if (!wfy.empty(fileList) && fileList.length > 0) {
				this.affixList = []
				fileList.forEach((file) => {
					this.affixList.push({
						affixId: wfy.uuid(22),
						indexEvalDtlId: this.currentEvalDtl.evalDtlId,
						affixPath: file.response,
						affixName: file.name
					})
				})
				this.affixList = Array.from(new Set(this.affixList))
				let affixPathList = []
				this.affixList.forEach((img) => {
					affixPathList.push(img.affixPath)
				})
				console.log('🚀 ~ affixPathList', affixPathList)
				this.affixListStr = affixPathList.length ? affixPathList.join(',') : ''
				loading.close()
			} else {
				this.affixList = []
				this.affixListStr = ''
				loading.close()
			}
		},
		// 复制概述
		copyBaseGs () {
			console.log('🚀 ~ 222', 222)
			wfy.copyToClipboard(this.currentEvalDtl.reginEvalLack)
		},
		submitForm (formName) {
			this.$refs[formName].validate((valid) => {
				if (valid) {

				} else {
					console.log('error submit!!')
					return false
				}
			})
		},
		resetForm (formName) {
			this.$refs[formName].resetFields()
		},
		// 获取score对应的level
		getLevelForScore (score) {
			if (wfy.empty(score)) {
				return ''
			} else {
				let level = this.anIndexAbilityOptionsList.find((item) => {
					return item.status === score
				})
				console.log('🚀 ~ level', level)
				return level.level
			}
		},
		// 获取能力选项为空的项目
		getScoreEmptyData () {
			// let emptyList = this.scoreList.filter((item) => {
			//     return item.score === "" || item.score === null
			// })
			// console.log('🚀 ~ emptyList', emptyList)
			// return emptyList;
			//
			// if(wfy.empty(currentEvalDtl.reginEvalScore)){
			//
			// }
			// 如果没有选择自评能力等级 返回true
			return wfy.empty(this.scoreList[0].score)
		},
		handleChangeSeq () {
			this.switchCurrEvalInfo('T')
		},
		before () {
			if (this.editProgress === 'main') {
				this.editProgress = 'detail'
			} else if (this.anIndexEvaluationMain.currQuestionSeq > 1) {
				if (this.controlType === 'city') {
					this.switchCurrEvalInfo('P')
				} else {
					this.saveDetail('P')
				}
			}
		},
		next () {
			if (this.controlType === 'city') {
				this.switchCurrEvalInfo('L')
			} else {
				this.saveDetail('L')
			}
			if (this.anIndexEvaluationMain.currQuestionSeq === this.anIndexEvaluationMain.totalQuestionNums) {
				this.editProgress = 'main'
			}
		},
		storageData () {
			if (this.editProgress === 'detail') {
				this.saveDetail('Tem')
			} else {
				this.saveMain(this.controlType, 'Tem')
			}
		},
		// 保存详细信息  type === Tem(暂存)
		saveDetail (type) {
			// let emptyList = this.getScoreEmptyData()
			// if (emptyList) {
			// 	this.$message.warning('自评能力等级不能为空！')
			// 	error
			// 	return
			// }
			if (this.controlType === 'expert' && wfy.empty(this.scoreList[0].expertScore) && type !== 'Tem') {
				this.$message.warning('请选择评估等级！')
				return
			}
			console.log('🚀 ~ this.scoreList', this.scoreList)
			this.scoreList.forEach((level) => {
				level.level = this.getLevelForScore(level.score)
				if (this.controlType === 'expert') {
					level.expertLevel = this.getLevelForScore(level.expertScore)
				}
			})

			this.$http({
				url: this.$http.adornUrl('/eval/saveDtl'),
				method: 'post',
				data: this.$http.adornData({
					'anIndexEvaluationDtl': {
						evalDtlId: this.currentEvalDtl.evalDtlId,
						evalMainId: this.currentEvalDtl.evalMainId,
						expertEvalBiz: this.currentEvalDtl.expertEvalBiz,
						expertEvalBy: this.currentEvalDtl.expertEvalBy,
						expertEvalLack: this.currentEvalDtl.expertEvalLack,
						evaluationDtlBiz: this.currentEvalDtl.evaluationDtlBiz,
						expertEvalScore: this.scoreList[0].expertScore,
						expertEvalTime: this.controlType === 'expert' ? wfy.format('yyyy-MM-dd HH:mm:ss', new Date()) : this.currentEvalDtl.expertEvalTime,
						expertEvayBy: this.controlType === 'expert' ? this.$store.state.user.name : this.currentEvalDtl.expertEvayBy,
						indexId: this.currentEvalDtl.indexId,
						reginEvalBiz: this.currentEvalDtl.reginEvalBiz,
						reginEvalLack: this.currentEvalDtl.reginEvalLack,
						reginEvalScore: this.scoreList[0].score,
						reginEvalTime: this.controlType === 'area' ? wfy.format('yyyy-MM-dd HH:mm:ss', new Date()) : this.currentEvalDtl.reginEvalTime,
						reginEvayBy: this.controlType === 'area' ? this.$store.state.user.name : this.currentEvalDtl.reginEvayBy,
						status: this.currentEvalDtl.status,
					},
					'scoreList': this.scoreList,
					'affixList': this.affixList //add by sjq增加一个上传附件的保存
				})
			}).then(({
				data
			}) => {
				console.log('🚀 ~ data', data)
				if (data && type === 'Tem') {
					this.$message.success('保存成功！')
				}
				if (data && type !== 'Tem') {
					this.switchCurrEvalInfo(type)
				}
			})
		},
		// 切换上一个下一个指标
		switchCurrEvalInfo (type) {
			console.log('🚀 ~ this.keyword', this.keyword)
			this.$http({
				url: this.$http.adornUrl('/eval/switchCurrEvalInfo'),
				method: 'post',
				data: this.$http.adornData({
					'operFlag': type,
					'evalMainId': this.currentEvalDtl.evalMainId,
					'evalCurrDtlId': this.currentEvalDtl.evalDtlId,
					'evalCurrDtlOrder': this.anIndexEvaluationMain.currQuestionSeq,
					'evalTotalDtlNums': this.anIndexEvaluationMain.totalQuestionNums,
					'toIndexNo': type === 'T' ? this.keyword : ''
				})
			}).then(({
				data
			}) => {
				if (data) {
					console.log('🚀 ~ this.switchdata', data)
					this.editFormData = wfy.deepCopy(data)
					// if(type === "T"){
					//     this.editProgress = "detail";
					// }
					if (type === 'T') {
						this.editProgress = 'detail'
					}
					this.initData()
				}
			})
		},
		// 保存主信息
		saveMain (type, storageFlag) {

			let evalStatus = this.anIndexEvaluationMain.evalStatus;
            let biz2 = "";
			if (type === 'city') {
				evalStatus = 'Y'
			} else if (type === 'province') {  //ADD BYSJQ 0126省级审批完成
				evalStatus = 'P'
			} else if (type === 'expert') {
				evalStatus = 'F'
			} else if(type === 'adminReturn'){
                evalStatus = 'P';
                biz2 = "N";
            } else if(type === 'admin'){
                biz2 = "Y";
            }
			//20240510修改BY宋加庆
			//if(storageFlag && storageFlag === "Tem"){
			//    evalStatus = 'P'
			//}
			let params = {
				'evalMainId': this.currentEvalDtl.evalMainId,
				'reginEvalDesc': this.anIndexEvaluationMain.reginEvalDesc,
				'auditDesc': this.anIndexEvaluationMain.auditDesc,
				'confirmDesc': this.anIndexEvaluationMain.confirmDesc,
				'expertLack': this.anIndexEvaluationMain.expertLack,
				'expertBiz': this.anIndexEvaluationMain.expertBiz,
				'currQuestionSeq': 1,
				'currQuestionId': this.currentEvalDtl.evalMainId + '_1',
				'evalStatus': evalStatus,
				'createBy': type === 'area' ? this.$store.state.user.name : this.anIndexEvaluationMain.createBy,
				'createTime': wfy.format('yyyy-MM-dd HH:mm:ss', new Date()),
				'lstUpdBy': this.$store.state.user.name,
				'lstUpdTime': wfy.format('yyyy-MM-dd HH:mm:ss', new Date()),
				'auditBy': type === 'city' ? this.$store.state.user.name : this.anIndexEvaluationMain.auditBy,
				'auditDate': type === 'city' ? wfy.format('yyyy-MM-dd HH:mm:ss', new Date()) : this.anIndexEvaluationMain.auditDate,
				'confirmBy': type === 'province' ? this.$store.state.user.name : this.anIndexEvaluationMain.auditBy,
				'confirmDate': type === 'province' ? wfy.format('yyyy-MM-dd HH:mm:ss', new Date()) : this.anIndexEvaluationMain.confirmDate,
				'evaluationMainBiz': this.anIndexEvaluationMain.evaluationMainBiz,
				'evaluationMainBizExpert': this.anIndexEvaluationMain.evaluationMainBizExpert,
				'evaluationMainResult1Expert': this.anIndexEvaluationMain.evaluationMainResult1Expert,
				'evaluationMainResult2Expert': this.anIndexEvaluationMain.evaluationMainResult2Expert,
				'evaluationMainResult3Expert': this.anIndexEvaluationMain.evaluationMainResult3Expert,
				'evaluationMainResult4Expert': this.anIndexEvaluationMain.evaluationMainResult4Expert,
                'biz2': biz2
			}
			this.$http({
				url: this.$http.adornUrl('/eval/updMainSelCol'),
				method: 'post',
				data: this.$http.adornData(params)
			}).then(({
				data
			}) => {
				if (data) {
					if (type === 'expert') {
						if (data === 'OK') {
							if (storageFlag && storageFlag === 'Tem') {
								this.$alert('暂存成功', '友情提醒')
							} else {
								this.$emit('success', {
									reginId: this.anIndexEvaluationMain.reginId,
									evalYear: this.anIndexEvaluationMain.evalYear,
									evalStatus: params.evalStatus
								})
							}
						} else {
							this.$alert(data, '友情提醒')
						}
					} else {
						if (data === 'OK') {
							if (storageFlag && storageFlag === 'Tem') {
								this.$alert('暂存成功', '友情提醒')
							} else {
								this.$emit('success', {
									reginId: this.anIndexEvaluationMain.reginId,
									evalYear: this.anIndexEvaluationMain.evalYear,
									evalStatus: params.evalStatus
								})
							}
						} else {
							this.$alert(data, '友情提醒')
						}
					}
				}
			})
		},
		// 区县保存填报进度
		allSave () {
			this.$alert('保存成功！', '友情提醒')
		},
		viewIndexDtl () {
			this.auditDtlVisible = true
			this.$nextTick(() => {
				this.$refs.auditdtl.init(this.currentEvalDtl.evalMainId)
			})
		},
		openMainBaseInfo () {
			this.baseinfoVisible = true
			this.$nextTick(() => {
				this.$refs.baseinfo.init(this.currentEvalDtl.evalMainId)
			})
		},
		// 市审批
		cityAudit () {
			this.saveMain('city')
		},
		// 省审批
		provinceAudit () {
			this.saveMain('province')
		},

		// 省市驳回
		cityReject () {
			this.$prompt('请输入驳回原因', '友情提醒', {}).then((res) => {
				console.log('🚀 ~ res', res)
				this.$http({
					url: this.$http.adornUrl('/eval/updMainSelCol'),
					method: 'post',
					data: this.$http.adornData({
						'evalMainId': this.currentEvalDtl.evalMainId,
						'evalStatus': 'N',
						'auditDesc': type === 'city' ? res.value : '',
						'confirmDesc': type === 'province' ? res.value : '',
						'currQuestionSeq': 1,
						'currQuestionId': this.currentEvalDtl.evalMainId + '_1',
						'lstUpdBy': this.$store.state.user.name,
						'lstUpdTime': wfy.format('yyyy-MM-dd HH:mm:ss', new Date())
					})
				}).then(({
					data
				}) => {
					this.$emit('reject')
				})
			})
		},
		// 专家审批保存
		expertAudit () {
			this.$confirm('完成评估后将产生最终评估报告，是否确认？', '友情提醒', {}).then(() => {
				this.saveMain('expert')
			})
		},
        // 管理员确认
        expertAdmin () {
            this.$confirm('确定要进行管理员确认吗？', '友情提醒', {}).then(() => {
                this.saveMain('admin')
            })
        },
        // 管理驳回
        returnAdmin(){
            this.$confirm('确定要进行管理员驳回吗？驳回后专家可以再次进行评审', '友情提醒', {}).then(() => {
                this.saveMain('adminReturn')
            })
        },
		// 返回列表页面
		returnList () {
			this.$confirm('要返回列表界面，是否确认？', '友情提醒', {}).then(() => {
				this.$emit('success', {
					reginId: this.anIndexEvaluationMain.reginId,
					evalYear: this.anIndexEvaluationMain.evalYear,
				})
			})
		},

	}
}
</script>

<style lang="scss" scoped>
.title {
  height: 40px;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 26px;
  font-width: bolder;
}

.el-textarea__inner::placeholder {
  color: #909399;
  text-align: center;
  vertical-align: middle;
}


.btn-box {
  display: flex;
  height: 60px;
  width: 100%;
  justify-content: space-between;
  align-items: center;
}

.sub-title {
  height: 40px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-around;
  font-size: 14px;
  margin-bottom: 10px;
  font-weight: bold;
  color: #909399;
}
</style>
